<template>
  <el-form :model="form" label-width="120px">
    <el-form-item label="学院名称">
      <el-input v-model="form.college_name" />
    </el-form-item>
    <el-form-item label="下属专业数">
      <el-input v-model="form.major_number" disabled/>
    </el-form-item>
    <el-form-item label="下属班级数">
      <el-input v-model="form.class_number" disabled/>
    </el-form-item>
    <el-form-item label="学院人数">
      <el-input v-model="form.college_p_number" disabled/>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm() ">确认修改</el-button>
      <el-button @click="closeDialog() ">取消</el-button>
    </el-form-item>
  </el-form>
</template>

<script>

export default {
  props: {
    currentCollege: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      form: {
        college_name: '',
        major_number: '',
        class_number: '',
        college_p_number: ''
      },

    };
  },
  methods: {
    submitForm() {
      this.$emit('submit-form',this.form);
    },
    closeDialog() {
      this.$emit('close-dialog');
    },
  },
  watch: {
    // 监听父组件传入的currentCollege变化
    currentCollege: {
      immediate: true,
      handler(newVal) {
        if (newVal) {
          // 将父组件传入的学生数据填充到表单中
          this.form = {
            college_name: newVal.college_name,
            major_number: newVal.major_number,
            class_number: newVal.class_number,
            college_p_number: newVal.college_p_number,
          }
        }
      }
    }
  },
};
</script>
